package CDIO2;

import java.util.Scanner;

public class Player {
	private String name;
	private Konto konto;
	private Field playerField;
	private boolean won;
	private boolean lost;
	private Dice[] dice = new Dice[2];
	
	public Player(String name){
		this.name = name;
		konto = new Konto();
		playerField = new Field(0);
		won = false;
		dice[0] = new Dice();
		dice[1] = new Dice();
	}
	
	public void doTurn(int index){
		Scanner sc = new Scanner(System.in);
		System.out.println("--------------------");
		System.out.println("Players turn: " + name);
		System.out.println("Throw dice by writing something and press enter");
		sc.next();
		System.out.println(konto.getPoints());
		if(index+playerField.getNumber()>=12){
			index = index - 12;
		}
		System.out.println("Dice Thrown: " + dice[0].getValue() +" & " + dice[1].getValue());
		playerField = new Field(playerField.getNumber()+index);
		if(playerField.getPoint()>0)
			konto.addPoints(playerField.getPoint());
		else
			konto.withdrawPoints(playerField.getPoint());
		System.out.println("You landed on " +playerField.getName() + " (" + playerField.getPoint() + ")");
		System.out.println(playerField.getMessege());
		System.out.println(konto.getPoints());
		System.out.println("--------------------");
	}
	
	public void throwDice(){
		dice[0].hit();
		dice[1].hit();
	}
	
	public Dice[] getDice(){
		return dice;
	}
	
	public Konto getKonto(){
		return konto;
	}
	public String getName(){
		return name;
	}
	
	public Field getPlayerField(){
		return playerField;
	}
	
	public int getPoints(){
		return konto.getPoints();
	}
	
	public boolean getWon(){
		if(konto.getPoints() >= 3000)
			won = true;
		else
			won = false;
		return won;
	}
	
	public boolean getLost(){
		if(konto.getPoints() == 0)
			lost = true;
		else
			lost = false;
		return lost;
	}

	public void setName(String name){
		this.name = name;
	}
	
	public void setName(){
		System.out.println("Write Name: ");
		Scanner sc = new Scanner(System.in);
		this.name = sc.nextLine();
	}
	@Override
	public String toString(){
		return name;
	}

}
